﻿using System;
using System.Drawing;
using System.Web.UI;
using BLL;
using Model;

public partial class ProductAging_ManuAging_AgingBox : System.Web.UI.Page
{    
    private Aging ag;
    private AgingInfo agi;
    private static string agingID;

    public ProductAging_ManuAging_AgingBox()
    {
        ag = new Aging();
        agi = new AgingInfo();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetData();
        }
    }

    private void GetData()
    {
        string Deviceno = Request.QueryString["deviceno"].ToString();
        this.Label1.Text = Deviceno;
        agi = ag.GetbyDeviceName(Deviceno);
        if (string.IsNullOrEmpty(agi.AgingID))
        {

        }
        else
        {
            this.Label2.ForeColor = Color.Blue;
            agingID = agi.AgingID;
            this.LinkButton1.Enabled = true;
            string url = "10.53.6.170/pa/ProductAging/ViewAging/AgingDetailforBoard.aspx?agingID=" + agingID;
            this.LinkButton1.Attributes.Add("onclick", "javascript:return window.open('http://" + url + "','AgingDetail','height=600,width=900,top=100,left=250,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')");

            TimeSpan datediff;
            if (string.IsNullOrEmpty(agi.TempStartManuUser))
            {
                datediff = agi.InBoxManuTime.AddMinutes(30).Subtract(DateTime.Now);
                if (datediff.TotalMinutes > 0)
                {
                    //升温倒计时
                    if (datediff.Minutes>=10)
                        this.Label2.Text = "00:" + datediff.Minutes.ToString();
                    else
                        this.Label2.Text = "00:0" + datediff.Minutes.ToString();
                }
                else
                {
                    //恒温开始提示
                    //this.Label2.Text = "00:00";
                    this.Button1.Enabled = true;
                    this.Button1.BackColor = Color.Red;
                }
            }
            else          //恒温开始已确认，恒温结束未确认
            {
                datediff = agi.TempStartManuTime.AddHours((double)agi.TimeSpec).Subtract(DateTime.Now);
                if (datediff.TotalMinutes > 0)
                {
                    //恒温倒计时
                    if (datediff.Hours >= 10)
                    {
                        if (datediff.Minutes >= 10)
                            this.Label2.Text = datediff.Hours.ToString() + ":" + datediff.Minutes.ToString();
                        else
                            this.Label2.Text = datediff.Hours.ToString() + ":0" + datediff.Minutes.ToString();
                    }
                    else
                    {
                        if (datediff.Minutes >= 10)
                            this.Label2.Text = "0" + datediff.Hours.ToString() + ":" + datediff.Minutes.ToString();
                        else
                            this.Label2.Text = "0" + datediff.Hours.ToString() + ":0" + datediff.Minutes.ToString();
                    }
                    if (string.IsNullOrEmpty(agi.PatrolManuUser))
                        this.Button4.Enabled = true;
                }
                else
                {
                    //恒温结束提示
                    //this.Label2.Text = "00:00";
                    this.Button2.Enabled = true;
                    this.Button2.BackColor = Color.Red;
                }
            }
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string str = ag.Aging_TempStartManu(agingID, User.Identity.Name);
        ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
        Response.Redirect(Request.Url.ToString()); 
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string str = ag.Aging_TempEndManu(agingID, User.Identity.Name);
        ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
        Response.Redirect(Request.Url.ToString()); 
    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        string str = ag.Aging_PatrolManu(agingID, User.Identity.Name);
        ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
        Response.Redirect(Request.Url.ToString()); 
    }
}
